<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>参数校验：构建安全可靠的系统基石</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .serif-font {
            font-family: 'Noto Serif SC', serif;
        }
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .code-block {
            background: #1e1e1e;
            border-radius: 12px;
            overflow: hidden;
        }
        .code-header {
            background: #2d2d2d;
            padding: 8px 16px;
            font-size: 12px;
            color: #888;
            border-bottom: 1px solid #444;
        }
        pre {
            margin: 0;
            padding: 16px;
            overflow-x: auto;
        }
        code {
            font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
            font-size: 14px;
            line-height: 1.6;
        }
        .floating-icon {
            animation: float 3s ease-in-out infinite;
        }
        @keyframes float {
            0%, 100% { transform: translateY(0px); }
            50% { transform: translateY(-10px); }
        }
        .section-divider {
            height: 2px;
            background: linear-gradient(to right, transparent, #e5e7eb, transparent);
            margin: 4rem 0;
        }
        ::selection {
            background: rgba(102, 126, 234, 0.2);
            color: #667eea;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-24 px-6">
        <div class="max-w-6xl mx-auto text-center">
            <div class="floating-icon inline-block mb-6">
                <i class="fas fa-shield-alt text-6xl opacity-90"></i>
            </div>
            <h1 class="text-5xl md:text-6xl font-bold mb-6 serif-font">参数校验</h1>
            <p class="text-xl md:text-2xl mb-8 opacity-90">构建安全可靠的系统基石</p>
            <div class="max-w-3xl mx-auto">
                <p class="text-lg leading-relaxed opacity-80">
                    参数校验是保证系统稳定性、安全性和用户体验的重要步骤。前端校验提供即时反馈，增强用户体验；而后端校验确保数据的完整性和系统的安全性。两者相辅相成，共同确保系统的高效运行和安全保护。
                </p>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-7xl mx-auto px-6 py-16">
        <!-- 数据可视化 -->
        <section class="mb-16">
            <div class="bg-white rounded-2xl shadow-lg p-8">
                <h2 class="text-3xl font-bold mb-8 text-center gradient-text">参数校验架构全景</h2>
                <div class="mermaid">
                    graph TB
                        A[用户输入] --> B[前端校验]
                        B --> C{校验通过?}
                        C -->|是| D[发送请求]
                        C -->|否| E[显示错误提示]
                        D --> F[后端校验]
                        F --> G{校验通过?}
                        G -->|是| H[业务处理]
                        G -->|否| I[返回错误响应]
                        I --> J[前端显示错误]
                        H --> K[返回成功响应]
                        
                        style A fill:#f9f,stroke:#333,stroke-width:2px
                        style B fill:#bbf,stroke:#333,stroke-width:2px
                        style F fill:#fbf,stroke:#333,stroke-width:2px
                        style H fill:#bfb,stroke:#333,stroke-width:2px
                </div>
            </div>
        </section>

        <!-- 前端参数校验 -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <i class="fas fa-laptop-code text-4xl text-purple-600 mr-4"></i>
                <h2 class="text-4xl font-bold serif-font">前端参数校验</h2>
            </div>
            
            <p class="text-lg text-gray-700 mb-8 leading-relaxed">
                前端校验可以提供良好的用户体验，并减少不必要的网络请求，但它不能替代后端校验，因为前端校验易被绕过。前端校验的主要方法包括：
            </p>

            <div class="grid md:grid-cols-2 gap-6">
                <!-- 格式校验 -->
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <div class="flex items-center mb-4">
                        <i class="fas fa-check-circle text-2xl text-green-500 mr-3"></i>
                        <h3 class="text-xl font-bold">格式校验</h3>
                    </div>
                    <p class="text-gray-600 mb-4">使用正则表达式校验电子邮件地址、电话号码、日期格式等。</p>
                    <div class="code-block">
                        <div class="code-header">JavaScript</div>
                        <pre><code class="text-gray-300">// 验证电子邮件地址
function validateEmail(email) {
    const regex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
    return regex.test(email);
}</code></pre>
                    </div>
                </div>

                <!-- 必填字段校验 -->
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <div class="flex items-center mb-4">
                        <i class="fas fa-asterisk text-2xl text-red-500 mr-3"></i>
                        <h3 class="text-xl font-bold">必填字段校验</h3>
                    </div>
                    <p class="text-gray-600 mb-4">确保用户填写了所有必填字段。</p>
                    <div class="code-block">
                        <div class="code-header">JavaScript</div>
                        <pre><code class="text-gray-300">// 验证必填字段
function validateRequired(field) {
    return field.value.trim() !== '';
}</code></pre>
                    </div>
                </div>

                <!-- 范围校验 -->
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <div class="flex items-center mb-4">
                        <i class="fas fa-ruler-horizontal text-2xl text-blue-500 mr-3"></i>
                        <h3 class="text-xl font-bold">范围校验</h3>
                    </div>
                    <p class="text-gray-600 mb-4">确保数字在特定范围内。</p>
                    <div class="code-block">
                        <div class="code-header">JavaScript</div>
                        <pre><code class="text-gray-300">// 验证数字范围
function validateRange(number, min, max) {
    return number >= min && number <= max;
}</code></pre>
                    </div>
                </div>

                <!-- 自定义规则 -->
                <div class="bg-white rounded-xl shadow-md p-6 card-hover">
                    <div class="flex items-center mb-4">
                        <i class="fas fa-cog text-2xl text-purple-500 mr-3"></i>
                        <h3 class="text-xl font-bold">自定义规则</h3>
                    </div>
                    <p class="text-gray-600 mb-4">根据业务规则实现自定义校验逻辑。</p>
                    <div class="code-block">
                        <div class="code-header">JavaScript</div>
                        <pre><code class="text-gray-300">// 自定义规则示例
function validateCustomRule(value) {
    return value.length >= 6; // 示例：密码至少6位
}</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <div class="section-divider"></div>

        <!-- 后端参数校验 -->
        <section class="mb-16">
            <div class="flex items-center mb-8">
                <i class="fas fa-server text-4xl text-indigo-600 mr-4"></i>
                <h2 class="text-4xl font-bold serif-font">后端参数校验</h2>
            </div>
            
            <p class="text-lg text-gray-700 mb-8 leading-relaxed">
                后端校验是确保数据安全性和一致性的关键部分，因为前端校验可以被绕过或篡改。后端校验的主要方法包括：
            </p>

            <div class="space-y-6">
                <!-- 格式校验 -->
                <div class="bg-white rounded-xl shadow-md p-6">
                    <div class="flex items-center mb-4">
                        <i class="fas fa-file-code text-2xl text-green-500 mr-3"></i>
                        <h3 class="text-xl font-bold">格式校验</h3>
                    </div>
                    <p class="text-gray-600 mb-4">校验字符串格式、日期格式、电话号码等。</p>
                    <div class="code-block">
                        <div class="code-header">Java/Spring Boot</div>
                        <pre><code class="text-gray-300">@RequestMapping("/submit")
public ResponseEntity&lt;String&gt; submit(@RequestParam @Email String email) {
    // 处理请求
}</code></pre>
                    </div>
                </div>

                <!-- 必填字段校验 -->
                <div class="bg-white rounded-xl shadow-md p-6">
                    <div class="flex items-center mb-4">
                        <i class="fas fa-clipboard-check text-2xl text-red-500 mr-3"></i>
                        <h3 class="text-xl font-bold">必填字段校验</h3>
                    </div>
                    <p class="text-gray-600 mb-4">检查请求体是否包含所有必需的字段。</p>
                    <div class="code-block">
                        <div class="code-header">Java/Spring Boot</div>
                        <pre><code class="text-gray-300">@PostMapping("/register")
public ResponseEntity&lt;String&gt; register(@RequestBody @Valid UserDto userDto) {
    // 处理请求
}</code></pre>
                    </div>
                </div>

                <!-- 范围校验 -->
                <div class="bg-white rounded-xl shadow-md p-6">
                    <div class="flex items-center mb-4">
                        <i class="fas fa-sort-numeric-up-alt text-2xl text-blue-500 mr-3"></i>
                        <h3 class="text-xl font-bold">范围校验</h3>
                    </div>
                    <p class="text-gray-600 mb-4">确保数值在预期范围内。</p>
                    <div class="code-block">
                        <div class="code-header">Java/Spring Boot</div>
                        <pre><code class="text-gray-300">@RequestMapping("/setAge")
public ResponseEntity&lt;String&gt; setAge(@RequestParam @Min(18) @Max(100) int age) {
    // 处理请求
}</code></pre>
                    </div>
                </div>

                <!-- 自定义规则 -->
                <div class="bg-white rounded-xl shadow-md p-6">
                    <div class="flex items-center mb-4">
                        <i class="fas fa-tools text-2xl text-purple-500 mr-3"></i>
                        <h3 class="text-xl font-bold">自定义规则</h3>
                    </div>
                    <p class="text-gray-600 mb-4">根据业务规则实现复杂的校验逻辑。</p>
                    <div class="code-block">
                        <div class="code-header">Java/Spring Boot</div>
                        <pre><code class="text-gray-300">@RequestMapping("/custom")
public ResponseEntity&lt;String&gt; customValidation(@RequestBody CustomRequest request) {
    if (!customValidationLogic(request)) {
        return ResponseEntity.badRequest().body("Custom validation failed");
    }
    // 处理请求
}</code></pre>
                    </div>
                </div>
            </div>
        </section>

        <div class="section-divider"></div>

        <!-- 前后端参数校验的配合 -->
        <section class="mb-16">
            <div class="bg-gradient-to-r from-purple-50 to-indigo-50 rounded-2xl p-8">
                <div class="flex items-center mb-8">